package com.shop.dingdongshoppingapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shop.dingdongshoppingapi.dao.RemarksDao;
import com.shop.dingdongshoppingapi.dto.RemarksAddDto;
import com.shop.dingdongshoppingapi.entity.Remarks;
import com.shop.dingdongshoppingapi.service.intf.RemarksService;
import com.shop.dingdongshoppingapi.vo.R;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RemarksServiceImpl implements RemarksService {
    @Resource
    private RemarksDao dao;
    /*
    * 讲备注内容新增到备注表*/
    @Override
    public R save(RemarksAddDto dto) {
        if(dto != null){
            if(dto.getContent()!=null && dto.getContent().length()> 0 && dto.getOid()>0){
                Remarks rewards = new Remarks();
                BeanUtils.copyProperties(dto,rewards);
                rewards.setOid(dto.getOid());
                if(dao.insert(rewards) > 0){
                    return R.ok();
                }
            }
        }
        return R.fail("亲，备注保存失败！");
    }
    /*
    * 查询某用户某个订单的备注*/
    @Override
    public R query(int oid) {
        if(oid > 0){
            QueryWrapper<Remarks> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("oid",oid);
            return R.ok(dao.selectList(queryWrapper));
        }
        return R.fail("亲，没有备注信息");
    }

}
